use std::error::FromError;
pub fn read_manifest(contents: &[u8], layout: Layout, source_id: &SourceId)
- -> CargoResult<(Manifest, Vec<Path>)> {
- util::toml::to_manifest(contents, source_id, layout).map_err(human)
+ -> CargoResult<(Manifest, Vec<Path>)> {
+ let root = layout.root.clone();
+ util::toml::to_manifest(contents, source_id, layout).map_err(|e| {
+ human(format!("failed to parse manifest at `{:?}`\n{}",
+ root.join("Cargo.toml"), e))
+ })
}
pub fn read_package(path: &Path, source_id: &SourceId)
#[derive(Clone)]
pub struct Layout {
- root: Path,
+ pub root: Path,
lib: Option<Path>,
bins: Vec<Path>,
examples: Vec<Path>,
Some(toml) => return Ok(toml),
None => {}
}
- let mut error_str = format!("could not parse input TOML\n");
+ let mut error_str = format!("could not parse input as TOML\n");
for error in parser.errors.iter() {
let (loline, locol) = parser.to_linecol(error.lo);
let (hiline, hicol) = parser.to_linecol(error.hi);
assert_that(p.cargo_process("build"),
execs()
.with_status(101)
- .with_stderr("Cargo.toml is not a valid manifest\n\n\
- No `package` or `project` section found.\n"))
+ .with_stderr("\
+failed to parse manifest at `[..]`
+Cargo.toml is not a valid manifest
+
+No `package` or `project` section found.
+"))
});
test!(cargo_compile_with_invalid_manifest2 {
assert_that(p.cargo_process("build"),
execs()
.with_status(101)
- .with_stderr("could not parse input TOML\n\
- Cargo.toml:3:19-3:20 expected a value\n\n"))
+ .with_stderr("\
+failed to parse manifest at `[..]`
+could not parse input as TOML
+Cargo.toml:3:19-3:20 expected a value
+
+"))
});
test!(cargo_compile_with_invalid_manifest3 {
.arg("src/Cargo.toml"),
execs()
.with_status(101)
- .with_stderr("could not parse input TOML\n\
- src[..]Cargo.toml:1:5-1:6 expected a value\n\n"))
+ .with_stderr("\
+failed to parse manifest at `[..]`
+could not parse input as TOML\n\
+src[..]Cargo.toml:1:5-1:6 expected a value\n\n"))
});
test!(cargo_compile_with_invalid_version {
assert_that(p.cargo_process("build"),
execs()
.with_status(101)
- .with_stderr("Cargo.toml is not a valid manifest\n\n\
- cannot parse '1.0' as a semver for the key \
- `project.version`\n"))
+ .with_stderr("\
+failed to parse manifest at `[..]`
+Cargo.toml is not a valid manifest
+
+cannot parse '1.0' as a semver for the key `project.version`
+"))
});
"#);
assert_that(p.cargo_process("build"),
execs().with_status(101)
- .with_stderr("either a [lib] or [[bin]] section \
- must be present\n"));
+ .with_stderr("\
+failed to parse manifest at `[..]Cargo.toml`
+either a [lib] or [[bin]] section must be present\n"));
});
test!(lto_build {
could not parse Toml manifest; path=[..]
Caused by:
- could not parse input TOML
+ could not parse input as TOML
[..].cargo[..]config:2:20-2:21 expected `=`, but found `i`
"));
.file("build.rs", r#"fn main() {}"#);
assert_that(p.cargo_process("build").arg("-v"),
execs().with_status(101)
- .with_stderr("either a [lib] or [[bin]] section must \
- be present"));
+ .with_stderr("\
+failed to parse manifest at `[..]`
+either a [lib] or [[bin]] section must be present"));
});
test!(shared_dep_with_a_build_script {
assert_that(project.cargo_process("build"),
execs()
.with_stdout("")
- .with_stderr(format!("Cargo.toml is not a valid manifest\n\n\
- invalid url `{}`: relative URL without a base\n", url)));
+ .with_stderr(format!("\
+failed to parse manifest at `[..]`
+Cargo.toml is not a valid manifest
+
+invalid url `{}`: relative URL without a base
+", url)));
});
test!(two_revs_same_deps {
assert_that(p.cargo_process("build"),
execs().with_status(101).with_stderr(format!("\
+failed to parse manifest at `[..]`
Cargo.toml is not a valid manifest
Feature `bar` includes `baz` which is neither a dependency nor another feature
assert_that(p.cargo_process("build"),
execs().with_status(101).with_stderr(format!("\
+failed to parse manifest at `[..]`
Cargo.toml is not a valid manifest
Features and dependencies cannot have the same name: `bar`
assert_that(p.cargo_process("build"),
execs().with_status(101).with_stderr(format!("\
+failed to parse manifest at `[..]`
Cargo.toml is not a valid manifest
Feature `bar` depends on `baz` which is not an optional dependency.
assert_that(p.cargo_process("build"),
execs().with_status(101).with_stderr(format!("\
+failed to parse manifest at `[..]`
Cargo.toml is not a valid manifest
Dev-dependencies are not allowed to be optional: `bar`
assert_that(p.cargo_process("build").arg("--features").arg("foo"),
execs().with_status(101).with_stderr(format!("\
+failed to parse manifest at `[..]`
Cargo.toml is not a valid manifest
Feature `foo` requires `bar` which is not an optional dependency
assert_that(p.cargo_process("build").arg("--features").arg("foo"),
execs().with_status(101).with_stderr(format!("\
+failed to parse manifest at `[..]`
Cargo.toml is not a valid manifest
Feature `foo` requires `bar` which is not an optional dependency